﻿using System;
using OneMG.Phoenix.Entity;
using OneMG.Phoenix.Respository;
using IBatisNet.DataMapper;
using OneMG.Phoenix.Kernel.IBatisUtil;
using System.Collections.Generic;
using System.Collections;

namespace OneMG.Phoenix.IBatisRepository
{
    public class NewsRepository : BaseIBatisDao,INews
    {
        public NewsRepository()
            : base("yihaoke_newMap.Config")
        {

        }
        public System.Int32 AddNews(ENews entity)
        {
			string stmtId = "NewsMap.InsertNews";
			 Object obj = base.SqlMapper.Insert(stmtId, entity);
			 return (System.Int32)obj;
        }
        
		public  ENews GetByNewsID (System.Int32 newsID)
        {
			string stmtId = "NewsMap.SelectByNewsID";
			return base.SqlMapper.QueryForObject<ENews>(stmtId, newsID);
        }
        
        public  void DeleteByNewsID (System.Int32 newsID)
        {
			string stmtId = "NewsMap.DeleteByNewsID";
			base.SqlMapper.Update(stmtId, newsID);
        }
        
        public  void UpdateByNewsID (ENews entity)
        {
			string stmtId = "NewsMap.UpdateByNewsID";
			base.SqlMapper.Update(stmtId, entity);
        }

        public IList<ENews> GetPagedList(int pageSize, int pageIndex, int categoryID,out int totalRecord)
        {
            Hashtable ht = new Hashtable();
            ht.Add("CateID", categoryID);

            totalRecord = base.SqlMapper.QueryForObject<int>("NewsMap.SelectAllRecord", ht);

            if (pageIndex > totalRecord)
                pageIndex = 1;

            int startPage = pageSize * pageIndex - pageSize;

            int endPage = pageSize * pageIndex;

            ht.Add("StartPage", startPage);
            ht.Add("EndPage", endPage);

            string stmtId = "NewsMap.SelectAllPagedList";

            return base.SqlMapper.QueryForList<ENews>(stmtId, ht);
           

        }


    }
}

